<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教练信息管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<!-- 顶部开始 -->
<div class="container">
    <div class="logo"><a href="./index.html">健身房管理系统 V1.1</a></div>
    <div class="open-nav"><i class="iconfont">&#xe699;</i></div>
    <ul class="layui-nav right" lay-filter="">
        <li class="layui-nav-item">
            <a href="javascript:;">管理员</a>
            <dl class="layui-nav-child">
                <dd><a href="${pageContext.request.contextPath}/member/outlogin.action">退出</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/index.jsp">前台首页</a></li>
    </ul>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 左侧菜单开始 -->
    <div class="left-nav">
        <div id="side-nav">
            <jsp:include page="left.jsp"/>
        </div>
    </div>
    <!-- 左侧菜单结束 -->
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content"  id="table">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="" >
                <div class="layui-form-pane" style="text-align: center;">
                    <div class="layui-form-item" style="display: inline-block;">
                        <label class="layui-form-label xbs768">日期范围</label>
                        <div class="layui-input-inline xbs768">
                            <input type="date" class="layui-input" placeholder="开会员最早时间" id="min">
                        </div>
                        <div class="layui-input-inline xbs768">
                            <input type="date" class="layui-input" placeholder="开会员最晚时间" id="max">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" id="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:80px">
                            <button type="button" class="layui-btn"  lay-submit="" lay-filter="" onclick="findMem()"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                </div>
            </form>
            <xblock>
                <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
<%--                <button class="layui-btn" onclick="member_add('添加用户','${pageContext.request.contextPath}/adminMem_add.jsp','600','550')"><i class="layui-icon">&#xe608;</i>添加</button>--%>
                <span class="x-right" style="line-height:40px">共有数据:${coachInfo.list.size()}条</span>
            </xblock>
            <table class="layui-table">
                <thead>
                <tr>
                    <th>
                        <input type="checkbox" name="allck" value="">
                    </th>
                    <th>ID</th>
                    <th>真实名字</th>
                    <th>性别</th>
                    <th>联系电话</th>
                    <th>住址</th>
                    <th>入职时间</th>
                    <th>教学方向</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${coachInfo.list}" var="coach">
                    <tr>
                        <td>
                            <input type="checkbox" value="${coach.coachid}" name="ck">
                        </td>
                        <td>${coach.coachid}</td>
                        <td>${coach.coachrealname}</td>
                        <td>${coach.coachsex}</td>
                        <td>${coach.coachLogName}</td>
                        <td>${coach.address}</td>
                        <td><fmt:formatDate value="${coach.hiredate}" pattern="yyyy.MM.dd"/></td>
                        <td>${coach.cotype}</td>
                        <td class="td-manage">
                            <a style="text-decoration:none" onclick="member_recover(${coach.coachid})" href="javascript:;" title="恢复">
                                <i class="layui-icon">&#xe618;</i>
                            </a>
                            &nbsp;&nbsp;
                            <a title="删除" href="javascript:;" onclick="member_del(${coach.coachid})"
                               style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                </c:forEach>

                </tbody>
            </table>
<%--            分页--%>
            <div id="bottom">
                <div>
                    <nav aria-label="..." style="text-align:center;">
                        <ul class="pagination layui-laypage" style="white-space: nowrap">
<%--                            向前翻页--%>
                            <li style="display: inline-block"><a href="javascript:ajaxsplit(${coachInfo.prePage})" aria-label="Previous">&laquo;</a></li>

                            <c:forEach begin="1" end="${coachInfo.pages}" var="i">
                                <c:if test="${coachInfo.pageNum==i}">
                                    <li style="display: inline-block">
                                        <a href="javascript:ajaxsplit(${i})"
                                           style="background-color: #DFDFDF">${i}</a>
                                    </li>
                                </c:if>
                                <c:if test="${coachInfo.pageNum!=i}">
                                    <li style="display: inline-block">
                                        <a href="javascript:ajaxsplit(${i})">${i}</a>
                                    </li>
                                </c:if>
                            </c:forEach>
<%--                            向后翻页--%>
                            <li style="display: inline-block"><a href="javascript:ajaxsplit(${coachInfo.nextPage})" aria-label="Previous">&raquo;</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->
<!-- 底部开始 -->
<div class="footer">
    <div class="copyright">Copyright ©2017 x-admin v2.3 All Rights Reserved. 本后台系统由X前端框架提供前端技术支持</div>
</div>
<!-- 底部结束 -->

<!-- 页面动态效果 -->
<script>
    //分页
    function ajaxsplit(page) {
        console.log(page);
        //异步ajax分页请求
        $.ajax({
            url:"${pageContext.request.contextPath}/admin/ajaxsplitCoach.action",
            data:{"page":page},
            type:"post",
            success:function () {
                //更新id=table部分内容
                $("#table").load("http://localhost:8080/GamnasiumSystem/adminCoach_list.jsp #table");
            }
        });
    }
    //多条件搜索，用Ajax发送请求,然后更新session=memInfo内容
    function findMem(){
        $.ajax({
            url: "${pageContext.request.contextPath}/admin/adminFindMem.action",
            type: "post",
            data: {
                datemin:$("#min").val(),
                datemax:$("#max").val(),
                memname:$("#username").val()
            },
            success:function (){
                //更新id=table部分内容
                $("#table").load("http://localhost:8080/GamnasiumSystem/adminCoach_list.jsp #table");
            },
            error:function (){
                console.log("error");
            }
        });
    }
    /*用户-删除*/
    function member_del(obj){
        console.log(obj);
        layer.confirm('确认要删除吗？',function(){
            //发异步删除数据
            $.ajax({
                url: "${pageContext.request.contextPath}/admin/deleteCo.action",
                type: "post",
                data: {
                    coachid:obj
                },
                success:function (result){
                    console.log(result);
                    if (result=="ok"){
                        window.top.location.href="http://localhost:8080/GamnasiumSystem/admin/toDeCoachList.action";
                    }else {
                        layer.msg('删除失败，请重试！',{icon:1});
                    }
                },
                error:function (){
                    console.log("error");
                }
            });
        });
    }
    /*用户-恢复*/
    function member_recover(obj){
        layer.confirm('确认要恢复吗？',function(){
            //发异步恢复数据
            $.ajax({
                url: "${pageContext.request.contextPath}/admin/deCoSt1.action",
                type: "post",
                data: {
                    coachid:obj
                },
                success:function (result){
                    console.log(result);
                    if (result=="ok"){
                        window.top.location.href="http://localhost:8080/GamnasiumSystem/admin/toCoachList.action";
                    }else {
                        layer.msg('删除失败，请重试！',{icon:1});
                    }
                },
                error:function (){
                    console.log("error");
                }
            });
            layer.msg('已恢复!',{icon:1,time:1000});
        });
    }
    //全选按钮
    $("input[name='allck']").click(function (){
        //全选
        var allck = $("input[name='allck']");
        //子复选框
        var ck = $("input[name='ck']");
        // console.log("ck:"+ck);
        if (allck.prop("checked")){
            //1.全选
            ck.prop("checked",true);
        }else {
            //2.反选
            ck.prop("checked",false);
        }
    });
    //3.子复选框非全选
    $("input[name='ck']").click(function (){
        //子复选框长度
        var ck = $("input[name='ck']");
        //全选
        var allck = $("input[name='allck']");
        //获取选中的子ck
        var cked = $("input:checkbox[name='ck']:checked");
        // console.log("ck:"+ck);
        // console.log(" cked:"+cked[0].value);
        if (cked.length!=ck.length){
            allck.prop("checked",false);
        }else {
            allck.prop("checked",true);
        }
    });
    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(){
            //捉到所有被选中的，发异步进行删除
            var cked = $("input:checkbox[name='ck']:checked");
            // console.log(cked[1].value);
            var memids = [];
            cked.each(function (){
                memids.push($(this).val());
                // console.log($(this).val());
            });
            $.ajax({
                url: "${pageContext.request.contextPath}/admin/delCoachBatch1.action",
                type: "post",
                data: {
                    //传字符串到后端
                    coachids:memids.toString()
                },
                success:function (result){
                    console.log(result);
                    if (result=="ok"){
                        window.top.location.href="http://localhost:8080/GamnasiumSystem/admin/toDeCoachList.action";
                    }else {
                        layer.msg('删除失败，请重试！',{icon:1});
                    }
                },
                error:function (){
                    console.log("error");
                }
            });
            layer.msg('删除成功', {icon: 1});
        });
    }
</script>
</body>
</html>
